/**
 * 
 */
package com.cea.papyrus.diagram.composite.command;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.uml2.uml.Connector;

import com.cea.papyrus.core.commands.connection.ConnectionCreateCommand;
import com.cea.papyrus.core.pseudoelement.UMLElementFactory;
import com.cea.papyrus.diagram.composite.pseudoelement.RoleBinding;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * Factory that creates ConnectionCreateCommand for edges. This subclass add
 * diagram specific commands.
 * 
 * @author dumoulin
 * 
 */
public class ConnectionCreateCommandFactory extends com.cea.papyrus.core.commands.factories.ConnectionCreateCommandFactory {

    /**
     * Singleton instance of the factory.
     */
    public static ConnectionCreateCommandFactory eINSTANCE = new ConnectionCreateCommandFactory();


    /**
     * 
     */
    @Override
    public ConnectionCreateCommand getConnectionCreateCommand(GraphElement source, Object newObjectDescription, Point location) {
  
        // find uml element type
        if (newObjectDescription instanceof UMLElementFactory) {
            UMLElementFactory enhancedType = (UMLElementFactory) newObjectDescription;
            type = enhancedType.getClazz();

        } else {
            type = (Class) newObjectDescription;
        }
        
        java.lang.Class eClass = (java.lang.Class) type;
        if (eClass.equals(Connector.class)) {
            return new ConnectorCreateCommand(source, newObjectDescription, location);
        }
        if (eClass.equals(RoleBinding.class)) {
            return new RoleBindingCreateCommand(source, newObjectDescription, location);
        }
        return super.getConnectionCreateCommand(source, newObjectDescription, location);
    }
}
